﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietPremier.Models;

namespace VietPremier.Controllers
{
    public class AboutUsController : Controller
    {
        //
        // GET: /AboutUs/

        public ActionResult Index()
        {
            using (dbVietPremierDataContext db = new dbVietPremierDataContext())
            {
                var query = from p in db.EntityAboutUs
                            join q in db.EntityListAboutUs on p.Id equals q.IdAboutUs
                            select new AboutUsModel
                            {
                                Id = q.Id,
                                Name = q.Name,
                                Description = q.Description,
                                Body = q.Body,
                                Image = q.Image,
                                IdAboutUs = p.Id,
                                AboutUsName = p.Name,
                                AboutUsBody = p.Body
                            };
                if (query.Count() != 0)
                {
                    ViewBag.Keyword = db.EntityAboutUs.FirstOrDefault(p => p.Id == 1).Meta_keyword;
                    ViewBag.Description = db.EntityAboutUs.FirstOrDefault(p => p.Id == 1).Meta_description;
                    ViewBag.TitleTag = db.EntityAboutUs.FirstOrDefault(p => p.Id == 1).Titletag;
                    ViewBag.AboutUsName = query.FirstOrDefault().AboutUsName;
                    ViewBag.AboutUsBody = query.FirstOrDefault().AboutUsBody;
                    return View(query.ToList());
                }
                else
                    return View("Error", "Destination");


            }
           
        }

    }
}
